package cn.iocoder.yudao.module.biz.controller.admin.emergencyRanks;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.biz.controller.admin.emergencyRanks.vo.*;
import cn.iocoder.yudao.module.biz.dal.dataobject.emergencyRanks.BizEmergencyRanksDO;
import cn.iocoder.yudao.module.biz.convert.emergencyRanks.BizEmergencyRanksConvert;
import cn.iocoder.yudao.module.biz.service.emergencyRanks.BizEmergencyRanksService;

@Api(tags = "管理后台 - 应急队伍")
@RestController
@RequestMapping("/biz/emergency-ranks")
@Validated
public class BizEmergencyRanksController {

    @Resource
    private BizEmergencyRanksService emergencyRanksService;

    @PostMapping("/create")
    @ApiOperation("创建应急队伍")
    @PreAuthorize("@ss.hasPermission('biz:emergency-ranks:create')")
    public CommonResult<String> createEmergencyRanks(@Valid @RequestBody BizEmergencyRanksCreateReqVO createReqVO) {
        return success(emergencyRanksService.createEmergencyRanks(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新应急队伍")
    @PreAuthorize("@ss.hasPermission('biz:emergency-ranks:update')")
    public CommonResult<Boolean> updateEmergencyRanks(@Valid @RequestBody BizEmergencyRanksUpdateReqVO updateReqVO) {
        emergencyRanksService.updateEmergencyRanks(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除应急队伍")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = String.class)
    @PreAuthorize("@ss.hasPermission('biz:emergency-ranks:delete')")
    public CommonResult<Boolean> deleteEmergencyRanks(@RequestParam("id") String id) {
        emergencyRanksService.deleteEmergencyRanks(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得应急队伍")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = String.class)
    @PreAuthorize("@ss.hasPermission('biz:emergency-ranks:query')")
    public CommonResult<BizEmergencyRanksRespVO> getEmergencyRanks(@RequestParam("id") String id) {
        BizEmergencyRanksDO emergencyRanks = emergencyRanksService.getEmergencyRanks(id);
        return success(BizEmergencyRanksConvert.INSTANCE.convert(emergencyRanks));
    }

    @GetMapping("/list")
    @ApiOperation("获得应急队伍列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
    @PreAuthorize("@ss.hasPermission('biz:emergency-ranks:query')")
    public CommonResult<List<BizEmergencyRanksRespVO>> getEmergencyRanksList(@RequestParam("ids") Collection<String> ids) {
        List<BizEmergencyRanksDO> list = emergencyRanksService.getEmergencyRanksList(ids);
        return success(BizEmergencyRanksConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @ApiOperation("获得应急队伍分页")
    @PreAuthorize("@ss.hasPermission('biz:emergency-ranks:query')")
    public CommonResult<PageResult<BizEmergencyRanksRespVO>> getEmergencyRanksPage(@Valid BizEmergencyRanksPageReqVO pageVO) {
        PageResult<BizEmergencyRanksDO> pageResult = emergencyRanksService.getEmergencyRanksPage(pageVO);
        return success(BizEmergencyRanksConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @ApiOperation("导出应急队伍 Excel")
    @PreAuthorize("@ss.hasPermission('biz:emergency-ranks:export')")
    @OperateLog(type = EXPORT)
    public void exportEmergencyRanksExcel(@Valid BizEmergencyRanksExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<BizEmergencyRanksDO> list = emergencyRanksService.getEmergencyRanksList(exportReqVO);
        // 导出 Excel
        List<BizEmergencyRanksExcelVO> datas = BizEmergencyRanksConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "应急队伍.xls", "数据", BizEmergencyRanksExcelVO.class, datas);
    }

}
